﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Net;
using System.IO;

namespace BLL
{
    public class ConnectionTool
    {
        #region 获取公网IP
        /// <summary>
        /// 获取公网IP
        /// </summary>
        /// <returns></returns>
        private string GetExternalIP()
        {
            string tempip = "";
            try
            {
                WebRequest wr = WebRequest.Create("http://www.ip138.com/ip2city.asp");
                Stream s = wr.GetResponse().GetResponseStream();
                StreamReader sr = new StreamReader(s, Encoding.Default);
                string all = sr.ReadToEnd(); //读取网站的数据

                int start = all.IndexOf("[") + 1;
                int end = all.IndexOf("]", start);
                tempip = all.Substring(start, end - start);
                sr.Close();
                s.Close();
            }
            catch
            {
            }
            return tempip;
        }

        #endregion


    }
}
